#include "checksentry.h"
#include "ui_checksentry.h"

CheckSentry::CheckSentry(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::CheckSentry)
{
    ui->setupUi(this);
    loadView();
}

CheckSentry::~CheckSentry()
{
    delete ui;
}

void CheckSentry::loadView()
{
    tableModel = new QSqlTableModel(this);
    tableModel->setTable("students");
    tableModel->setSort(Student_Class, Qt::AscendingOrder);
    tableModel->setHeaderData(Student_Number, Qt::Horizontal, tr("Number"));
    tableModel->setHeaderData(Student_Class, Qt::Horizontal, tr ("Class"));
    tableModel->setHeaderData(Student_Name, Qt::Horizontal, tr("Name"));
    tableModel->setHeaderData(Student_Sentry1, Qt::Horizontal, tr("Sentry1"));
    tableModel->setHeaderData(Student_Sentry2, Qt::Horizontal, tr("Sentry2"));
    tableModel->setHeaderData(Student_Sentry3, Qt::Horizontal, tr("Sentry3"));
    tableModel->setHeaderData(Student_Sentry4, Qt::Horizontal, tr("Sentry4"));
    tableModel->setHeaderData(Student_SentryT, Qt::Horizontal, tr("SentryT"));
    tableModel->setHeaderData(Student_SentryP, Qt::Horizontal, tr("SentryP"));
    tableModel->select();

    ui->tableView->setModel(tableModel);
    ui->tableView->setSelectionMode(QAbstractItemView::SingleSelection);
    ui->tableView->setSelectionBehavior(QAbstractItemView::SelectItems);
    ui->tableView->setColumnHidden(Student_ID,      true);
    ui->tableView->setColumnHidden(Student_Number,  false);
    ui->tableView->setColumnHidden(Student_Class,   false);
    ui->tableView->setColumnHidden(Student_Name,    false);
    ui->tableView->setColumnHidden(Student_Sentry1, false);
    ui->tableView->setColumnHidden(Student_Sentry2, false);
    ui->tableView->setColumnHidden(Student_Sentry3, false);
    ui->tableView->setColumnHidden(Student_Sentry4, false);
    ui->tableView->setColumnHidden(Student_SentryT, false);

    ui->tableView->resizeColumnsToContents();
    ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);

    QHeaderView *header = ui->tableView->horizontalHeader();
    header->setStretchLastSection(true);
}
